class Admin::OwnPowersController < Admin::ApplicationController
  before_action :set_own_power, only: [:show, :edit, :update, :destroy]

  # GET /admin/own_powers
  def index
    @own_powers = OwnPower.all
  end

  # GET /admin/own_powers/1
  def show
  end

  # GET /admin/own_powers/new
  def new
    @own_power = OwnPower.new
  end

  # GET /admin/own_powers/1/edit
  def edit
  end

  # POST /admin/own_powers
  def create
    @own_power = OwnPower.new(own_power_params.merge({admin_user_id: current_admin_user_id, company_id: current_company_id}))

    if @own_power.save
      redirect_to [:admin, @own_power], notice: 'Own power was successfully created.'
    else
      render :new
    end
  end

  # PATCH/PUT /admin/own_powers/1
  def update
    if @own_power.update(own_power_params)
      redirect_to [:admin, @own_power], notice: 'Own power was successfully updated.'
    else
      render :edit
    end
  end

  # DELETE /admin/own_powers/1
  def destroy
    @own_power.destroy
    redirect_to admin_own_powers_url, notice: 'Own power was successfully destroyed.'
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_own_power
      @own_power = OwnPower.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def own_power_params
      params.require(:own_power).permit(:company_id, :admin_user_id, :order_number, :img, :title, :content)
    end
end
